package net.learn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysJudgeQuery;
import net.learn.system.query.SysPaperQuery;
import net.learn.system.service.SysJudgeService;
import net.learn.system.service.SysPaperService;
import net.learn.system.vo.SysJudgeVO;
import net.learn.system.vo.SysPaperVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 试卷管理
 */
@RestController
@RequestMapping("sys/paper")
@Tag(name="试卷管理")
@AllArgsConstructor
public class SysPaperController {
    @Autowired
    private final SysPaperService sysPaperService;

    @GetMapping("getPaper")
    @Operation(summary = "分页获取试卷列表")
    public Result<PageResult<SysPaperVO>> getPaper(@Valid SysPaperQuery query){
        PageResult<SysPaperVO> page = sysPaperService.qryPaperListPage(query);

        return Result.ok(page);
    }
    @PostMapping("getPaperArray")
    @Operation(summary = "分页获取考试试卷列表")
    public Result<PageResult<SysPaperVO>> getPaperArray(@RequestBody SysPaperQuery query){
        PageResult<SysPaperVO> list = sysPaperService.qryPaperListArray(query);

        return Result.ok(list);
    }
    @PostMapping("getPaperList")
    @Operation(summary = "获取试卷列表")
    public Result<List<SysPaperVO>> getJudgeList(@RequestBody SysPaperQuery query){
        List<SysPaperVO> list = sysPaperService.qryPaperList();

        return Result.ok(list);
    }
    @PostMapping("qryPaperQuestionList")
    @Operation(summary = "获取试卷详情")
    public Result<List<SysPaperVO>> qryPaperQuestionList(@RequestBody SysPaperQuery query){
        List<SysPaperVO> list = sysPaperService.qryPaperQuestionList(query);

        return Result.ok(list);
    }
    @PostMapping("getMyScoreList")
    @Operation(summary = "获取我的考试成绩列表")
    public Result<List<SysPaperVO>> getMyScoreList(@RequestBody SysPaperQuery query){
        List<SysPaperVO> list = sysPaperService.qryMyScoreList(query);

        return Result.ok(list);
    }
    @PostMapping("qryPaperQuestionTypeList")
    @Operation(summary = "获取我的考试成绩列表")
    public Result<List<SysPaperVO>> qryPaperQuestionTypeList(@RequestBody SysPaperQuery query){
        List<SysPaperVO> list = sysPaperService.qryPaperQuestionTypeList(query);

        return Result.ok(list);
    }
    @PostMapping("/updatePaper")
    @Operation(summary = "修改试卷")
    public Result<String> updatePaper(@RequestBody @Valid SysPaperVO vo){
        sysPaperService.updatePaper(vo);

        return Result.ok();
    }
    @PostMapping("save")
    @Operation(summary = "新增试卷")
    public Result<String> addPaper(@RequestBody SysPaperVO vo){
        sysPaperService.addPaper(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    public Result<String> deleteById(@RequestBody List<Long> idList){
        sysPaperService.delete(idList);
        return Result.ok();
    }
}

